
cc.Class({
    extends: cc.Component,

    properties: {

    },

    // LIFE-CYCLE CALLBACKS:
    // onLoad () {},

    start () {
        this.time = 0
        this.Swaying = false
        this.period = 2
        setTimeout(()=>{
            //this.sway()
        },3000)
    },

    sway(){
        this.Swaying = true
    },

    adjustPosition(time){
        let resContent = this.node.getChildByName('mask').getChildByName('背景-AnimationCancel')
        if(resContent){
            for(let i=0;i<resContent.children.length;i++){
                this.recursiveCatch(resContent.children[i],time)
            }
        }
    },
    recursiveCatch(node,time){
        if(node.getComponent(cc.Sprite)){
            node.rotation = Math.sin(time*2*Math.PI/this.period)*10
        }
        
        if(node.children.length==0){
            return
        }else{

            for(let i=0;i<node.children.length;i++){
                this.recursiveCatch(node.children[i],time+0.3)
            }
            
        }
    },

    update (dt) {
        if(this.Swaying){
            this.time +=dt
            this.adjustPosition(this.time)
        }
    },
});
